package day02;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import day01.DBUtil2;

/**
 * ResultSet查询结果集
 */
public class JDBCDemo6 {
	public static void main(String[] args) {
		try{
			Connection conn=DBUtil2.getConnection();
			Statement state=conn.createStatement();
			String sql="SELECT empno,ename,sal,deptno FROM emp";
			ResultSet rs=state.executeQuery(sql);
			while(rs.next()){
				/*
				 * 不推荐，因为可读性差
				 * 参数表示结果集中第几个字段
				 */
			
				int empno=rs.getInt(1);
				String ename=rs.getString(2);
				int sal=rs.getInt(3);
				int deptno=rs.getInt(4);
				System.out.println(empno+","+ename+","+sal+","+deptno);
				
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
